﻿
@{
    ViewBag.Title = "注册商户";
    Layout = "~/Views/Shared/_UnLoginLayout.cshtml";
    var isreg = new HmPMer.Business.SysConfigBll().GetConfigVaule("RegIsOpen");
}
<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <div id="divradio1" class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>个人</div></div>
            <div id="divradio2" class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>企业</div></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
        <input type="text" name="MobilePhone" id="MobilePhone" lay-verify="phone" placeholder="手机号码" class="layui-input" onkeyup="this.value=this.value.replace(/[^\d{1-9}{1}\d{0-9}]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d{1-9}{1}\d{0-9}]/g,'')" />
    </div>
    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-xs7">
                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                <input type="text" name="ImgCode" id="ImgCode" lay-verify="required" placeholder="图形验证码" class="layui-input">
            </div> <div class="layui-col-xs5">
                <div style="margin-left: 10px;">
                    <img id="" src="/DrawingApi/GetValidateImg?codeKey=hmerpmreg&t=@DateTime.Now.Ticks" onclick="this.src = '/DrawingApi/GetValidateImg?codeKey=hmerpmreg&t=' + Math.random();" width="100" height="40" style="cursor:pointer" />
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-xs7">
                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-smscode"></label>
                <input type="text" name="SmsCode" id="SmsCode" lay-verify="required" placeholder="短信验证码" class="layui-input">
            </div>
            <div class="layui-col-xs5"> <div style="margin-left: 10px;"> <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="GetSmsCode">获取验证码</button> </div> </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="pwd1" id="pwd1" lay-verify="pass" placeholder="密码" class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
        <input type="password" name="pwd2" id="pwd2" lay-verify="required" placeholder="确认密码" class="layui-input">
    </div>
    @*<div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
        <input type="text" name="MerName" id="MerName" lay-verify="MerName" placeholder="商户名" class="layui-input">
    </div>*@
    <div class="layui-form-item">
        <a href="/account/login" class="layadmin-user-jump-change layadmin-link">用已有帐号登入</a>
    </div>
    @if (isreg.Equals("1"))
    {
    <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" id="btnSubmit" lay-filter="btnSubmit">注 册</button>
    </div>
    }
</div>
<script>
    function SetHtml(type) {
        var html1 = '<i class="layui-anim layui-icon"></i><div>个人</div>';
        var html2 = '<i class="layui-anim layui-icon"></i><div>个人</div>';
        var html3 = '<i class="layui-anim layui-icon"></i><div>企业</div>';
        var html4 = '<i class="layui-anim layui-icon"></i><div>企业</div>';
        $("#divradio1").removeClass("layui-form-radioed");
        $("#divradio2").removeClass("layui-form-radioed");
     
        if (type == 1) {
            $("#divradio1").html(html1);
            $("#divradio1").addClass("layui-form-radioed");
            $("#divradio2").html(html4);
        }

        if (type == 2) {
            $("#divradio2").html(html3);
            $("#divradio2").addClass("layui-form-radioed");
            $("#divradio1").html(html2);
        }
    }

    var AccountType = 0;

    $(function () {
        $("#divradio1").click(function () {         
            SetHtml(1);
            AccountType = 0;
        });
        $("#divradio2").click(function () {
            SetHtml(2)
            AccountType = 1;
        });

        var codeClick = false;
        //发送短信验证码
        $("#GetSmsCode").click(function () {

            if (codeClick) {
                return;
            }
            var Mobile = $("#MobilePhone").val();

            if (Mobile == '') {
                layer.msg('请输入手机', { icon: 5 });
                $('#MobilePhone').focus();
                return;
            }

            if (!validate.isMobile(Mobile)) {
                layer.msg('手机号格式错误！', { icon: 5 });
                $('#MobilePhone').focus();
                return false;
            }

            var ImgCode = $.trim($("#ImgCode").val());
            if (ImgCode == '') {
                layer.msg('请输入图片验证码', { icon: 5 });
                $('#ImgCode').focus();
                return;
            }

            if (ImgCode.length != 4) {
                layer.msg('验证码输入错误', { icon: 5 });
                $('#ImgCode').focus();
                return;
            }


            //获取短信验证码
            $.post("/DrawingApi/SendMobileCode", { "Mobile": Mobile, "SmsKey": "smshmerpmreg", "ImgCode": ImgCode, "ImgCodeKey": "hmerpmreg", SmsCode:"smscode", type: 1 }, function (data) {
                if (data.IsSuccess) {
                    layer.msg('获取短信验证码成功', { icon: 5 });
                    codeClick = true;
                    var showText = '%s s后获取';
                    var $this = $("#GetSmsCode");

                    if ($this.data('alt_button_disable_rendered') == 0) {
                        return false;
                    }
                    setTimeout(function () {
                        var count = 60;
                        setText();
                        $this.addClass("cur");
                        function setText() {
                            $this.html(showText.replace('%s ', count));

                            if (count > 0) {
                                count--;
                                $this.data('alt_button_disable_rendered', 0);
                                setTimeout(setText, 1000);
                            } else {
                                codeClick = false;
                                $this.html('重新获取');
                                $this.data('alt_button_disable_rendered', 1);
                            }
                        }
                    }, 10);

                } else {
                    layer.msg(data.message, { icon: 5 });
                    return false;
                }

            });
            return;
        });

        $("#btnSubmit").click(function () {
            Submint();
        });

        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];

            if (e && e.keyCode == 13) { // enter 键
                //要做的事情
                Submint();
            }
        };

    });

    function Submint() {
        var MobilePhone = $("#MobilePhone").val();

        if (MobilePhone == '') {
            layer.msg('请输入手机', { icon: 5 });
            $('#MobilePhone').focus();
            return;
        }

        if (!validate.isMobile(MobilePhone)) {
            layer.msg('手机号格式错误！', { icon: 5 });
            $('#MobilePhone').focus();
            return false;
        }

        var SmsCode = $.trim($("#SmsCode").val());

        if (SmsCode == '') {
            layer.msg('请输入短信验证码', { icon: 5 });
            $("#SmsCode").focus();
            return;
        }

        var pwd1 = $("#pwd1").val();

        if (pwd1 == '') {
            layer.msg('请输入密码', { icon: 5 });
            $('#pwd1').focus();
            return;
        }

        if (pwd1.length < 6 || pwd1.length > 18) {
            layer.msg('密码只能6-18位', { icon: 5 });
            $('#pwd1').focus();
            return;
        }

        var pwd2 = $("#pwd2").val();

        if (pwd2 == '') {
            layer.msg('请确认密码', { icon: 5 });
            $('#pwd2').focus();
            return;
        }

        if (pwd1 != pwd2) {
            layer.msg('两次密码不一致', { icon: 5 });
            $('#pwd2').focus();
            return;
        }

        //var MerName = $("#MerName").val();


        //if (MerName == '') {
        //    layer.msg('请输入商户名称！', { icon: 5 });
        //    $('#MerName').focus();
        //    return;
        //}

        $.post("/Account/Regedit", { 'AccountType': AccountType, 'MobilePhone': MobilePhone, 'Pass': pwd1, 'QQ': SmsCode }, function (d) {
            if (d.IsSuccess) {
                layer.msg('注册成功！', { icon: 5 });
                setTimeout(function () {
                    window.location = "/Account/Login"
                }, 1200);
                return;
            } else {
                layer.msg(d.message, { icon: 5 });
                return;
            }
        });
    }
</script>